
import 'package:flutter/material.dart';

//缩进显示组件 
class IndentWidget extends StatefulWidget{
  String text;
  List<Widget> childs=[];

  IndentWidget({super.key,required this.text});

  @override
  State<IndentWidget> createState() => IndentState();

  void appendChilds(List<Widget> popWidgets) {
      childs = popWidgets;
  }
}

class IndentState extends State<IndentWidget>{
  bool isOpen = true;
  
  @override
  Widget build(BuildContext context) {
      
      return Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            InkWell(
              onTap: () {
                  setState(() {
                    isOpen =!isOpen;
                  });
              },
              child:  Text(
                widget.text+(isOpen ? "":"..."),
                style: TextStyle(fontWeight: FontWeight.bold),
              )
            ),
            Visibility(
              visible: isOpen, 
              child: Container(
                padding: EdgeInsets.only(left: 30),
                child:Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: widget.childs
                ) 
              )
            )
          ],
        );
  }
}